package com.sqfw.project.wpReport.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sqfw.common.utils.StringUtils;
import com.sqfw.project.wp.domain.WpVisitInfo;
import com.sqfw.project.wpReport.domain.SeatServiceReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sqfw.framework.aspectj.lang.annotation.Log;
import com.sqfw.framework.aspectj.lang.enums.BusinessType;
import com.sqfw.project.wpReport.domain.VisitQualityReport;
import com.sqfw.project.wpReport.service.IVisitQualityReportService;
import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.framework.web.domain.AjaxResult;
import com.sqfw.common.utils.poi.ExcelUtil;

/**
 * 回访质量政务类报表Controller
 * 
 * @author lx
 * @date 2023-07-26
 */
@RestController
@RequestMapping("/wpReport/visitQualityReport")
public class VisitQualityReportController extends BaseController
{
    @Autowired
    private IVisitQualityReportService visitQualityReportService;

    /**
     * 查询回访质量政务类报表列表
     */
    @PreAuthorize("@ss.hasPermi('getVisitQualityReportList')")
    @GetMapping("/getVisitQualityReportList")
    public AjaxResult getVisitQualityReportList(WpVisitInfo wpVisitInfo)
    {
        List<VisitQualityReport> list = visitQualityReportService.getVisitQualityReportList(wpVisitInfo);


        if (StringUtils.isNotEmpty(list)){

            VisitQualityReport report = new VisitQualityReport();
            report.setVisitType("总计");
            //回访工单数
            int visitCount = list.stream()
                    .map(VisitQualityReport::getVisitCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setVisitCount(visitCount);

            //成功
            int visitSucessCount = list.stream()
                    .map(VisitQualityReport::getVisitSucessCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setVisitSucessCount(visitSucessCount);


            //满意
            int satisCount = list.stream()
                    .map(VisitQualityReport::getSatisCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setSatisCount(satisCount);


            //一般
            int kindCount = list.stream()
                    .map(VisitQualityReport::getKindCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setKindCount(kindCount);

            //不满意
            int unsatisCount = list.stream()
                    .map(VisitQualityReport::getUnsatisCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setUnsatisCount(unsatisCount);

            list.add(report);
        }



        return AjaxResult.success(list);
    }

    /**
     * 导出回访质量政务类报表列表
     */
    @Log(title = "回访质量政务类报表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('visitQualityReport:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, WpVisitInfo wpVisitInfo)
    {
        List<VisitQualityReport> list = visitQualityReportService.getVisitQualityReportList(wpVisitInfo);
        ExcelUtil<VisitQualityReport> util = new ExcelUtil<VisitQualityReport>(VisitQualityReport.class);
        util.exportExcel(response, list, "回访质量政务类报表数据");
    }


}
